package com.brspace.qualitycontrol.service.impl;

import com.brspace.qualitycontrol.entity.Plusclass;
import com.brspace.qualitycontrol.mapper.LeaveMapper;
import com.brspace.qualitycontrol.mapper.PlusclassMapper;
import com.brspace.qualitycontrol.service.PlusclassService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.brspace.qualitycontrol.utils.EmptyUtil;
import com.brspace.qualitycontrol.utils.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-04-02
 */
@Service
public class PlusclassServiceImpl extends ServiceImpl<PlusclassMapper, Plusclass> implements PlusclassService {
    @Resource
    private PlusclassMapper plusclassMapper;
    @Resource
    private LeaveMapper leaveMapper;
    /**
     * 新建加班申请
     * @param plusclass
     * @return
     */
    @Override
    public R addPlus(Plusclass plusclass) {
        if (EmptyUtil.isEmpty(plusclass.getTitle())) {
            throw new SecurityException("加班标题不能为空！");
        }
        if (EmptyUtil.isEmpty(plusclass.getDegree())) {
            throw new SecurityException("加班紧急程度不能为空！");
        }
        if (EmptyUtil.isEmpty(plusclass.getUsername())) {
            throw new SecurityException("姓名不能为空！");
        }
        if (EmptyUtil.isEmpty(plusclass.getDept())) {
            throw new SecurityException("部门不能为空！");
        }
        if (EmptyUtil.isEmpty(plusclass.getTypes())) {
            throw new SecurityException("加班类型为空！");
        }
        if (EmptyUtil.isEmpty(plusclass.getStartDate())) {
            throw new SecurityException("加班开始日期不能为空！");
        }
        if (EmptyUtil.isEmpty(plusclass.getStartTime()) ) {
            throw new SecurityException("加班开始时间不能为空！");
        }
        if (EmptyUtil.isEmpty(plusclass.getEndDate())) {
            throw new SecurityException("结束日期不能为空！");
        }
        if (EmptyUtil.isEmpty(plusclass.getEndTime())) {
            throw new SecurityException("结束时间不能为空！");
        }
        if (EmptyUtil.isEmpty(plusclass.getText())) {
            throw new SecurityException("请假原因不能为空！");
        }
        if (plusclassMapper.insert(plusclass)>0) {
            return R.ok().message("成功");
        }
        return R.error().message("失败");
    }

    /**
     * 加班请假列表
     * @return
     */
    @Override
    public List<Plusclass> findAll() {
        return null;
    }
}
